package cn.edu.lingnan.lsqn.service;

import java.util.Date;

import javax.inject.Inject;

import org.springframework.stereotype.Service;

import cn.cdahua.basic.model.Pager;
import cn.edu.lingnan.lsqn.dao.ISongDao;
import cn.edu.lingnan.lsqn.model.LsqnException;
import cn.edu.lingnan.lsqn.model.Song;

@Service("songService")
public class SongService implements ISongService {

	private ISongDao songDao;
	
	public ISongDao getSongDao() {
		return songDao;
	}

	@Inject
	public void setSongDao(ISongDao songDao) {
		this.songDao = songDao;
	}

	@Override
	public void add(Song song) {
		if(song.getName()==null||"".equals(song.getName())){
			throw new LsqnException("您没有输入歌曲名哦！！");
		}
		songDao.add(song);
	}

	@Override
	public void update(int id) {
		Song song = songDao.load(id);
		if(song.getStatus()==0){
			song.setPlayDate(new Date());
			song.setStatus(1);			
		}
		else{
			song.setStatus(0);
			song.setPlayDate(null);			
		}
		songDao.update(song);
	}

	@Override
	public Pager<Song> find() {
		return songDao.find();
	}

	@Override
	public Pager<Song> findByUserId(int id) {
		return songDao.findByUserId(id);
	}

	@Override
	public void delete(int id) {
		songDao.delete(id);
	}

}
